import os
import sys


def is_none(obj, default):
    if obj is None:
        return default
    else:
        return obj


# 获取启动路径（包下的方法调用，会包含包的路径）
def get_start_path():
    # determine if application is a script file or frozen exe
    if getattr(sys, 'frozen', False):
        # 未打包的路径
        return os.path.dirname(sys.executable)
    elif __file__:
        return os.path.dirname(__file__)


def get_base_path():
    # 是否Bundle Resource
    if getattr(sys, 'frozen', False):
        # 单个exe解药后的路径
        base_path = sys._MEIPASS
    else:
        # 不打包，正常执行的路径
        base_path = os.path.abspath(".")
    return base_path


def get_resources(file):
    base_path = get_base_path()
    res_file = os.path.join(base_path, "resources", file)
    return res_file


def get_exe_abs():
    # determine if application is a script file or frozen exe
    if getattr(sys, 'frozen', False):
        # 未打包的路径
        return sys.executable
    elif __file__:
        return __file__
